
#include "LCD12864.h"
#include "intrins.h"

void lcd12864_write_cmd(u8 cmd)
{
	LCD12864_RS=0;
	LCD12864_RW=0;
	LCD12864_E=0;
	LCD12864_DATAPORT=cmd;
	delay_ms(1);
	LCD12864_E=1;
	_nop_();
	LCD12864_E=0;
	LCD12864_RS=1;
	LCD12864_RW=1;			
}

void lcd12864_write_data(u8 dat)
{
	LCD12864_RS=1;
	LCD12864_RW=0;
	LCD12864_E=0;
	LCD12864_DATAPORT=dat;
	delay_ms(1);
	LCD12864_E=1;
	_nop_();
	LCD12864_E=0;
	LCD12864_RS=0;
	LCD12864_RW=0;
}

void lcd12864_init(void)
{
	LCD12864_PSB=1;
	lcd12864_write_cmd(0x06);
	lcd12864_write_cmd(0x0c);
	lcd12864_write_cmd(0x30);
	lcd12864_write_cmd(0x01);	
}

void lcd12864_clear(void)
{
	lcd12864_write_cmd(0x01);
}

void lcd12864_show_string(u8 x,u8 y,u8 *str)
{

	if(y<0||y>3)
	{
		return;
	}
	x&=0x0f;
	switch(y)
	{
		case 0: 
		{
			x|=0x80;
			break;
		}
		case 1: 
		{
			x|=0x90;
			break;
		}
		case 2: 
		{
			x|=0x88;
			break;
		}
		case 3: 
		{
			x|=0x98;
			break;
		}
	}
	lcd12864_write_cmd(x);
	while(*str!='\0')
	{
		lcd12864_write_data(*str);
		str++;
	}
}

